package com.github.tangmonkmeat;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Description:
 *
 * @author zwl
 * @version 1.0
 * @date 2021/8/21 下午9:15
 */
public class 石头碰撞的最小剩余大小 {

    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            int n = sc.nextInt();
            int[] wi = new int[n];
            for(int i = 0;i < n;i++){
                wi[i] = sc.nextInt();
            }
            Arrays.sort(wi);
            int num = wi.length;
            int tem = -1;
            for(int j = wi.length - 1;j > 0 && num > 1;){
                if(tem <= 0){
                    int y = wi[j];
                    int x = wi[j - 1];
                    tem = y - x;
                    j -= 2;
                    num -= 2;
                }else{
                    tem = Math.abs(tem - wi[j]);
                    j--;
                    num--;
                }
            }
            System.out.println(tem == -1 ? wi[0] : tem);
        }
    }

}
